Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(clients): make POST body related to the endpoint, assert body in tests #849

Merged
merged 4 commits into from
Jul 20, 2022

Conversation

shortcuts
Copy link
Member

@shortcuts shortcuts commented Jul 18, 2022

🧭 What and Why

🎟 JIRA Ticket: https://algolia.atlassian.net/browse/DI-321

The issue was discovered in #823, but I've moved the fix for the clients here.

Changes included:

The goal of this PR is to assert the body of each requests in the CTS even when we don't expect to have one.

On some POST requests, the body can be optional (e.g. browse), but needs to be a valid JSON object, when no body is expected at all (e.g. clearAllSynonyms), an empty string is considered as valid. In any case, an empty object ('{}') is considered as valid. Some endpoints do not expect a body at all, so we need to move that logic at the method level since it can't be factorized.

Issue

  1. Calling the browse method with only an indexName throws an empty body error
  2. Calling the clearRules method with a body throws an unexpected body error

Next

Fix null body for GET and DELETE methods on the PHP client, once @damcou is back: https://algolia.atlassian.net/browse/APIC-591

🧪 Test

  • CI
  • Playground:
    • deleteApiKey for the DELETE method change
    • browse with empty object only for the POST method change

@shortcuts shortcuts requested review from millotp and a team July 18, 2022 14:25
@shortcuts shortcuts self-assigned this Jul 18, 2022
@shortcuts shortcuts requested review from damcou and removed request for a team July 18, 2022 14:25
@netlify
Copy link

netlify bot commented Jul 18, 2022

Deploy Preview for api-clients-automation canceled.

Name Link
🔨 Latest commit 8ee4c28
🔍 Latest deploy log https://app.netlify.com/sites/api-clients-automation/deploys/62d828bed62260000894b1cb

@algolia-bot
Copy link
Collaborator

algolia-bot commented Jul 18, 2022

✗ The generated branch has been deleted.

If the PR has been merged, you can check the generated code on the main branch.
You can still access the code generated on main via this commit.

millotp
millotp previously approved these changes Jul 18, 2022
Copy link
Collaborator

@millotp millotp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good ! Hopefully all endpoints accept that !

@shortcuts
Copy link
Member Author

Looks good ! Hopefully all endpoints accept that !

Doing more tests on the DELETE side before merging

@shortcuts shortcuts force-pushed the fix/clients-empty-body-request branch from 9b758b5 to eca2fc5 Compare July 18, 2022 16:12
@shortcuts shortcuts changed the title fix(clients): send empty object on empty request body fix(clients): valid JSON on empty body, assert empty body on DELETE requests Jul 18, 2022
@shortcuts shortcuts requested a review from millotp July 18, 2022 16:29
Copy link
Collaborator

@millotp millotp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good for java and php ! But you are still getting undefined for js

templates/java/tests/requests/requests.mustache Outdated Show resolved Hide resolved
@shortcuts
Copy link
Member Author

Looks good for java and php ! But you are still getting undefined for js

Yup I'm importing the echoRequester fixes from the other PR, just making sure it works properly

@shortcuts shortcuts requested a review from millotp July 19, 2022 07:37
@shortcuts shortcuts force-pushed the fix/clients-empty-body-request branch from 81e42dc to 2903221 Compare July 19, 2022 07:44
@shortcuts shortcuts marked this pull request as draft July 20, 2022 07:09
@shortcuts shortcuts changed the title fix(clients): valid JSON on empty body, assert empty body on DELETE requests fix(clients): assert request body on every tests Jul 20, 2022
@shortcuts shortcuts force-pushed the fix/clients-empty-body-request branch from 94464cc to bfc99ff Compare July 20, 2022 14:48
@shortcuts shortcuts changed the title fix(clients): assert request body on every tests fix(clients): make POST body related to the endpoint, assert body in tests Jul 20, 2022
@shortcuts shortcuts marked this pull request as ready for review July 20, 2022 15:13
Copy link
Collaborator

@millotp millotp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GG !

@@ -50,7 +50,8 @@ private function normalize($options)
'headers' => [
'x-algolia-application-id' => $this->config->getAppId(),
'x-algolia-api-key' => $this->config->getAlgoliaApiKey(),
'User-Agent' => $this->config->getAlgoliaAgent() !== null
'User-Agent' =>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the php changes can be moved to another PR until @damcou is back

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changes for the PHP client here still fixes the POST methods that were not working previously (e.g. browse). However, I've removed the transporter/CTS changes in the meantime

tests/output/javascript/yarn.lock Show resolved Hide resolved
@shortcuts shortcuts requested a review from millotp July 20, 2022 16:14
Copy link
Collaborator

@millotp millotp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good !

@shortcuts shortcuts merged commit a4346a7 into main Jul 20, 2022
@shortcuts shortcuts deleted the fix/clients-empty-body-request branch July 20, 2022 16:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants